﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using DM_Article.Model;

namespace DM_Article.Bll
{
    public class bigclassbll
    {
        public static int add(SqlConnection conn, bigclass model)
        {
            SqlCommand cmd = new SqlCommand("insert into bigclass(bigclassname)values('" + model.bigclassname + "')", conn);
            object obj = cmd.ExecuteNonQuery();
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        public static int update(SqlConnection conn, bigclass model)
        {
            SqlCommand cmd = new SqlCommand("update bigclass set bigclassname ='" + model.bigclassname + "' where bigclassid='" + model.bigclassid + "'", conn);
            return cmd.ExecuteNonQuery();
        }

        public static int delete(SqlConnection conn, string bigclassid)
        {
            SqlCommand cmd = new SqlCommand("delete bigclass where bigclassid='" + bigclassid + "'", conn);
            return cmd.ExecuteNonQuery();
        }


        public static bigclass getBigclassDetail(SqlConnection conn, string bigclassid)
        {
            SqlDataAdapter da = new SqlDataAdapter("select [bigclassname] from bigclass where bigclassid='" + bigclassid + "'", conn);
            DataTable dt = new DataTable();
            bigclass model = new bigclass();
            da.Fill(dt);
            if (dt != null && dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["bigclassname"].ToString() != "")
                {
                    model.bigclassname = dt.Rows[0]["bigclassname"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }

        }

        public static DataTable getBigclassTable(SqlConnection conn)
        {
            SqlDataAdapter da = new SqlDataAdapter("select [bigclassid],[bigclassname] from bigclass", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }
    }
}
